using System;
using System.Collections.Generic;
using System.Text;
using ExampleApplication;
using Axiom.Core;
using Axiom.Math;
using Axiom.Graphics;

namespace Game.Main
{
    class AxiomSystem : /* ExampleApplication.ExampleApplication*/ AxiomEngineWrapper, IEngineSystem
    {
        public AxiomSystem()
        {

        }

        protected override void CreateScene()
        {
            //SceneManager.AmbientLight = new ColorEx(1, 1, 1);
            //SceneManager.SetSkyDome(true, "Skys.material", 0.5f, 0.5f);
            Entity ent1 = SceneManager.CreateEntity("Robot", "robot.mesh");
            //SceneNode robotNode = SceneManager.RootSceneNode.CreateChildSceneNode("RobotNode");

            Entity ent2 = SceneManager.CreateEntity("Robot2", "robot.mesh");
            //SceneNode node2 = SceneManager.RootSceneNode.CreateChildSceneNode("RobotNode2", new Vector3(50, 0, 0));
            
            //node2.AttachObject(ent2);

            //robotNode.AttachObject(ent1);

            Light light;
            light = SceneManager.CreateLight("Light1");
            light.Type = LightType.Point;
            light.Position = new Vector3(0.0f, 150.0f, 250.0f);
            
            light.Diffuse = new ColorEx(1.0f, 0.0f, 0.0f);
            light.Specular = new ColorEx(1.0f, 0.0f, 0.0f);

            SceneManager.AmbientLight = new ColorEx(0.2f, 0.2f, 0.2f);
            SceneManager.ShadowTechnique = ShadowTechnique.TextureModulative;

//            Entity entityNinja;
//            entityNinja = SceneManager.CreateEntity("Ninja", "ninja.mesh");
//            entityNinja.CastShadows = true;
//            SceneManager.RootSceneNode.CreateChildSceneNode("NinjaNode").AttachObject(entityNinja);

//            Plane plane = new Plane(Vector3.UnitY, 0.0f);

//            MeshManager.Instance.CreatePlane("ground", plane, 1500.0f, 1500.0f,
//                                 20, 20, true, 1, 5.0f, 5.0f, Vector3.UnitZ);

			SceneManager.LoadWorldGeometry(string.Format("Resources{0}Terrain.xml", System.IO.Path.DirectorySeparatorChar));
			SceneManager.SetSkyDome( true, "Examples/CloudySky", 5, 8 );
			
//            Entity entityGround;
//            entityGround = SceneManager.CreateEntity("GroundEntity", "ground");
//            SceneManager.RootSceneNode.CreateChildSceneNode().AttachObject(entityGround);
//            entityGround.MaterialName = "Examples/Rockwall";
//            entityGround.CastShadows = false;
        }

        #region IEngineRunner Members

        public void Init()
        {
            //base.Setup();
        }

        public void Start()
        {
            this.Run();
        }

        public void Quit()
        {
            if (Root != null)
            {
                Root.Dispose(); 
            }
            //this.Quit();
        }

        #endregion
    }
}
